@extends('backstage.layout.master')
@section('title', '品牌列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="backstage/brand/brand-list">品牌</a>
            </li>
            <li>
                品牌列表
            </li>
        </ul><!-- .breadcrumb -->
        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                品牌
                <small>
                    <i class="icon-double-angle-right"></i>
                    品牌列表
                </small>
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>品牌Id</th>
                            <th>品牌名称</th>
                            <th>品牌logo</th>
                            <th>品牌类型</th>
                            <th class="hidden-480">品牌描述</th>
                            <th>排序</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($brands as $brand)
                        <tr class="" data-tr-id="{{isset($brand->brand_id)?$brand->brand_id:''}}">
                            <td class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </td>
                            <td>{{isset($brand->brand_id)?$brand->brand_id:''}}</td>
                            <td>
                                {{isset($brand->brand_name)?$brand->brand_name:''}}
                            </td>
                            <td><img src="{{$brand->logo}}" width="30" height="30"></td>
                            <td>
                                @if(isset($brand->user_id)&&($brand->user_id==0))
                                    系统后台创建
                                @else
                                  品牌商
                                @endif
                            </td>
                            <td class="hidden-480">
                                {{str_limit($brand->description, $limit = 15, $end = '...')}}
                            </td>
                            <td style="width:68px;">
                                <input type="text" name="sort" value="{{$brand->sort}}" class="sort" style="width:50px;">
                                <input type="hidden" value="{{$brand->sort}}">
                                <input type="hidden" value="{{$brand->id}}">
                            </td>
                            <td>
                                <div class="visible-md visible-lg hidden-sm hidden-xs btn-group">

                                    <button onclick="javascript:window.location.href='{{asset('')}}backstage/brand/update-brand?brand_id={{isset($brand->brand_id)?$brand->brand_id:''}}';" class="btn btn-xs btn-info" data-rel="tooltip" title="修改">
                                        <i class="icon-edit bigger-120"></i>
                                    </button>

                                    <button class="btn btn-xs btn-danger" data-delete="{{isset($brand->brand_id)?$brand->brand_id:''}}" data-rel="tooltip" title="删除">
                                        <i class="icon-trash bigger-120"></i>
                                    </button>
                                </div>
                                <div class="visible-xs visible-sm hidden-md hidden-lg">
                                    <div class="inline position-relative">
                                        <button class="btn btn-minier btn-primary dropdown-toggle"
                                                data-toggle="dropdown">
                                            <i class="icon-cog icon-only bigger-110"></i>
                                        </button>

                                        <ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">

                                            <li>
                                                <a target="_blank" href="/backstage/brand/update-brand?brand_id={{isset($brand->brand_id)?$brand->brand_id:''}}" class="tooltip-success" data-rel="tooltip" title=""
                                                   data-original-title="修改">
													<span class="green">
													<i class="icon-edit bigger-120"></i>
													</span>
                                                </a>
                                            </li>
                                            <li>
                                                <a target="_blank" href="javascript:void(0) ;"  class="tooltip-error" data-delete="{{isset($brand->brand_id)?$brand->brand_id:''}}" data-rel="tooltip" title=""
                                                   data-original-title="删除">
													<span class="red">
														<i class="icon-trash bigger-120"></i>
													</span>
                                                </a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $brands->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $('[data-rel=tooltip]').tooltip();
            $('[data-delete]').click(function(){
                var  brand_id = $(this).attr("data-delete");
                console.log('brand_id:'+brand_id);
                bootbox.setLocale("zh_CN");
                bootbox.confirm({
                    size: 'small',
                    message: "你确定要删除吗？",
                    callback: function(result){
                        if(result)
                        {
                            $.post("/backstage/brand/delete-brand",
                                    {
                                        brand_id:brand_id,
                                        _token:"{{csrf_token()}}"
                                    },
                                    function(data){
                                        if(data.state==1)
                                        {
                                            $('[data-tr-id='+brand_id+']').remove();
                                            showMessage('','删除成功');
                                        }else {
                                            showMessage('',data.message);
                                        }
                                    });
                        }
                    }
                });

            });
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            this.checked = that.checked;
                            $(this).closest('tr').toggleClass('selected');
                        });

            });

            $(".sort").blur(function(){
                var sort = $(this).next().val();
                var newSort = $(this).val();
                var id = $(this).next().next().val();
                var a = $(this);
                if(newSort == sort){
                    return;
                }else{
                    $.ajax({
                        type: "POST",
                        url: "backstage/brand/update-sort",
                        data:{"sort":newSort,"id":id},
                        success: function(msg){
                            if(msg.state == "M00000"){
                                a.next().val(newSort);
                                showMessage("","修改成功！");
                            }else{
                                showMessage(msg.message,"");
                            }
                        },
                        error:function(){
                            showMessage("修改失败!","");
                        }
                    });
                }
            });
        });
    </script>
@stop